<template>
  <div>
    <!-- 模糊查询 -->
    <el-row>
      <el-form :inline="true" :model="search" class="demo-form-inline">
                <el-input v-if="false" v-model="search.pageNo"></el-input>
                <el-input v-if="false" v-model="search.pageSize"></el-input>
                <el-col :span="4">
                    <el-input v-model="search.clientName" placeholder="请输入客户名称"></el-input>
                </el-col>
                <el-col :span="12"
                    ><div>
                        <el-button type="primary" icon="el-icon-search" @click="searchBtn">搜索</el-button>
                        <el-button type="info" icon="el-icon-loading" @click="emptyBtn">刷新</el-button>
                    </div>
                </el-col></el-form
            >
    </el-row>
    <!-- 功能列表 -->
    <el-row>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="clientname" label="客户名字"> </el-table-column>
        <el-table-column prop="car_name" label="车名"> </el-table-column>
        <el-table-column prop="startTime" label="开始时间"> </el-table-column>
        <el-table-column prop="endTime" label="结束时间"> </el-table-column>
        <el-table-column prop="total_price" label="总金额"> </el-table-column>
        <el-table-column prop="shopname" label="租赁门店"> </el-table-column>
        <el-table-column prop="order_no" label="订单标号"> </el-table-column>
        <el-table-column label="操作" width="250">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </el-row>
    <!-- 分页 -->
    <el-row>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[2, 3, 5, 10, 100, 200, 300, 400]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-row>
  </div>
</template>
<script>
export default {
  data() {
    return {
      //数据
      tableData: [],
      search: { pageNo: 1, pageSize: 5 },
      currentPage: 1,
      pageSize: 5,
      total: 20,
      formLabelWidth: "80px",
      clientname: "",
      leaseTime:""
    };
  },
  created: function () {
    this.loadData();
  },
  methods: {
    //方法
    //加载数据的方法
    loadData: function () {
      var _this = this;
      //初始化数据
      this.$http
        .post("http://localhost:9999/cars/order/queryAll", { 
            pageNo: this.search.pageNo,
            pageSize: this.search.pageSize,
            clientName: this.search.clientName
        })
        .then(function (response) {
          // handle success  处理成功，回调的方法
          //console.log(response);
          //赋值分页列表
          _this.tableData = response.data.data.list;
          //删除最后一页为空时，调到上一页
          //alert(_this.tableData.length);
          if (_this.tableData.length == 0 && _this.currentPage != 1) {
            _this.currentPage = _this.currentPage - 1;
            _this.loadData();
          }
          //赋值总条数
          _this.total = response.data.data.total;
        })
        .catch(function (error) {
          // handle error 处理异常
          //console.log(error);
        })
        .then(function () {
          // always executed  总是执行  相当于finally
        });
    },
    //每页数量发生变化时
    handleSizeChange: function (v) {
      this.pageSize = v;
      this.loadData();
    },
    //当前页数放生变化是
    handleCurrentChange: function (v) {
      this.currentPage = v;
      this.loadData();
    },
    // 搜索方法
    search: function () {
      this.currentPage = 1;
      this.loadData();
    },
    //跳转更新
    toEdit: function (index, row) {
      //清空原来的
      this.form.avatar = "";
      this.form = row;
      this.updateFormVisible = true;
    },
    
    //删除
    handleDelete: function (index, row) {
      var _this = this;
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$http
            .delete(
              "http://localhost:9999/cars/order/delete?orderid=" + row.id
            )
            .then(function (response) {
              console.log(response);
              if (response.status == 200) {
                if (response.data.data) {
                  //提示成功
                  _this.$message({
                    type: "success",
                    message: "删除成功!",
                  });
                  //重新加载数据
                  _this.loadData();
                }
              }
            })
            .catch(function (error) {
              console.log(error);
              _this.$message.error("你错了。。。");
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
   
    getShowStatus(row, column, cellValue) {
      return cellValue == 0 ? "有" : "无";
    },
    getfactoryStatus(row, column, cellValue) {
      return cellValue == 0 ? "是" : "否";
    },
    flush() {
      //刷新当前页
      location.reload();
    },
  },
};
</script>

<style>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 100px;
  height: 100px;
  line-height: 100px;
  text-align: center;
}
.avatar {
  width: 100px;
  height: 100px;
  display: block;
}
</style>
